import * as Cesium from "cesium";
import "cesium/Build/Cesium/Widgets/widgets.css";

class Earth {
	private _container: string;
	protected _cesiumViewer: Cesium.Viewer;
	constructor(container: string) {
		this._container = container;
		this._cesiumViewer = new Cesium.Viewer(this._container, {
			// terrainProvider: Cesium.createWorldTerrain(),
		});
	}

	/**
	 * 获取版本号
	 * @returns 版本号
	 */
	public get version(): string {
		return "1.0.0";
	}

	/**
	 * 飞行到指定位置
	 * @param position 位置信息
	 */
	public flyTo(
		position: { lng: number; lat: number; alt: number },
		orientation: { heading: number; pitch: number; roll: number }
	) {
		this._cesiumViewer.camera.flyTo({
			destination: Cesium.Cartesian3.fromDegrees(
				position.lng,
				position.lat,
				position.alt
			),
			orientation: {
				heading: Cesium.Math.toRadians(orientation.heading),
				pitch: Cesium.Math.toRadians(orientation.pitch),
				roll: Cesium.Math.toDegrees(orientation.roll),
			},
		});
	}

	/**
	 *  视图切换到指定位置
	 * @param position 位置信息
	 */
	public setView(
		position: { lng: number; lat: number; alt: number },
		orientation: { heading: number; pitch: number; roll: number }
	) {
		this._cesiumViewer.camera.setView({
			destination: Cesium.Cartesian3.fromDegrees(
				position.lng,
				position.lat,
				position.alt
			),
			orientation: {
				heading: Cesium.Math.toRadians(orientation.heading),
				pitch: Cesium.Math.toRadians(orientation.pitch),
				roll: Cesium.Math.toDegrees(orientation.roll),
			},
		});
	}

	/**
	 *  设置视图的方位
	 * @param orientation	方位信息
	 */
	public setOrientation(orientation: {
		heading: number;
		pitch: number;
		roll: number;
	}) {
		this._cesiumViewer.camera.setView({
			orientation: {
				heading: Cesium.Math.toRadians(orientation.heading),
				pitch: Cesium.Math.toRadians(orientation.pitch),
				roll: Cesium.Math.toDegrees(orientation.roll),
			},
		});
	}
}

export default Earth;
